<div class="form_container">
    <h1>Upload New Users</h1>
    
<form action='.' method='post'>{% csrf_token %}

<table>
	{% if ProcessedHeaders %}
	    <tr><th>Data Preview</th><td colspan="100%">
	    <table><tr>
	    {% for header in ProcessedHeaders %}
		<th class="heading">{{header}}</th>
	    {% endfor %}
	    {% for row in ProcessedData %}
		<tr>
		    {% for item in row %}
			{% if forloop.counter == 1 %}
			    {% if item %}<td class="errorlist" title="There is an error with this user's information. Please see error message below.">&#9760;{% else %}<td class="noerror">&#10003;{% endif %}</td>
			{% else %}{% if forloop.counter == 2%}
			    {% if item %}<td>&#10003;</td>{% else %}<td class="errorlist" title="This user already exists. Creation of this user will be skipped.">&#9760;</td>{% endif %}
			{% else %}
			    <td>{{item}}</td>
			{% endif %}{% endif %}
		    {% endfor %}
		</tr>
	    {% endfor %}
	    </tr></table>
	    </tr>
	    {% if Errors %}
		<tr>
		    <th colspan="100%">Errors:</th>
		</tr>
		{% for error in Errors %}
		    <tr><td></td>
			<td colspan="100%">{{error}}</td>
		    </tr>
		{% endfor %}
	    {% else %}
		<tr>
			<td></td><td colspan="100%">
			{% if ProcessedHeaders and not Errors %}{{form.email_users.label}} {{form.email_users}} {{form.email_users.errors}} <br> {{form.email_users.help_text}}{% endif %}
		<tr>
		    <td></td><td colspan="100%">
		    {% if ProcessedHeaders and not Errors %}<button type="submit" class="button SaveButton floatleft" name="Save" value="Create" title="Create these users"><a>Create</a></button>{% endif %}
		    </td>
		</tr>
		{% endif %}
	{% else %}
		{% if Errors %}
			<tr>
		    <th></th><th colspan="100%" style="color: red;">Errors:</th>
		</tr>
		{% for error in Errors %}
		    <tr><td></td>
			<td colspan="100%">{{error}}</td>
		    </tr>
		{% endfor %}
		{% endif %}
	{% endif %}
	
{{form.as_table}}
<tr>
    <td colspan="4" class="Buttons">
        <button type="submit" class="button SaveButton floatleft" name="Save" value="Preview" title="Preview Uploaded Data"><a>Preview</a></button>
        <a class="button SaveButton" href="{% course_url management app='users' %}">Cancel</a>
    </td>
</tr>
<table>
</form>
</div>
